package com.kyexpress.vms.enitity;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

import javax.swing.table.DefaultTableModel;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import java.util.stream.Collectors;

public class DataCenter {
    public static final String DICT_URI = "/lookupValue/map/byLookup/";
    public static String DESCRIPTION="";
    public static String SELECT_TEXT;
    public static Project project;
    public static Module module;
    
    /**
     * 笔记列表集合
     */
    public static List<Dict> DICT_LIST = new LinkedList<>();
    
    private static String[] COLUMN_NAME = {"字段名称", "key", "value"};
    
    public static DefaultTableModel TABLE_MODEL = new DefaultTableModel(null, COLUMN_NAME) {
        @Override
        public boolean isCellEditable(int row, int column) {
            if (column != 0) {
                return false;
            } else {
                return true;
            }
        }
    };
    
    
    public static void reset() {
        int size = DICT_LIST.size();
        DICT_LIST.clear();
        for (int i = 0; i < size; i++) {
            TABLE_MODEL.removeRow(0);
        }
    }
    
    public static void fill() {
        for (Dict dict : DICT_LIST) {
            TABLE_MODEL.addRow(toStringArray(dict));
        }
    }
    
    private static Vector<String> toStringArray(Dict dict) {
        Vector<String> vector = new Vector<>();
        vector.add(dict.getFieldName());
        vector.add(dict.getDictKey());
        vector.add(dict.getDictValue());
        return vector;
    }
    
    @NotNull
    public static String getFileName() {
        String[] s = DataCenter.SELECT_TEXT.split("_");
        List<String> strings = Arrays.asList("vms", "storage");
        return Arrays.stream(s).filter(item -> !strings.contains(item)).map(item -> captureName(item)).collect(Collectors.joining())+"Enum";
    }
    
    
    private static String captureName(String str) {
        // 进行字母的ascii编码前移，效率要高于截取字符串进行转换的操作
        char[] cs = str.toCharArray();
        cs[0] -= 32;
        return String.valueOf(cs);
    }
    
    
}
